import java.util.*;

public class SortTest {
	public static void orderArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			array[i] = i;
		}
	}

	public static void notOrderArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			array[i] = array.length-i;
		}
	}
	public static void notOrderArrayRandom(int[] array) {
		Random random = new Random();
		for (int i = 0; i < array.length; i++) {
			array[i] = random.nextInt(10_0000);
		}
	}
	public static void testInsertSort(int[] array) {
		int[] tmpArray = Arrays.copyOf(array,array.length);

		long startTime = System.currentTimeMillis();
		Sort.insertSort(tmpArray);
		long endTime = System.currentTimeMillis();
		System.out.println("插入排序耗时："+ (endTime-startTime));
	}

	public static void testShellSort(int[] array) {
		int[] tmpArray = Arrays.copyOf(array,array.length);

		long startTime = System.currentTimeMillis();
		Sort.shellSort(tmpArray);
		long endTime = System.currentTimeMillis();
		System.out.println("希尔排序耗时："+ (endTime-startTime));
	}

	public static void testSelectSort(int[] array) {
		int[] tmpArray = Arrays.copyOf(array,array.length);
		long startTime = System.currentTimeMillis();
		Sort.selectSort(tmpArray);
		long endTime = System.currentTimeMillis();
		System.out.println("选择排序耗时："+ (endTime-startTime));
	}

	public static void testHeapSort(int[] array) {
		int[] tmpArray = Arrays.copyOf(array,array.length);
		long startTime = System.currentTimeMillis();
		Sort.heapSort(tmpArray);
		long endTime = System.currentTimeMillis();
		System.out.println("堆排序耗时："+ (endTime-startTime));
	}

	public static void testQuickSort(int[] array) {
		int[] tmpArray = Arrays.copyOf(array,array.length);
		long startTime = System.currentTimeMillis();
		Sort.quickSort(tmpArray);
		long endTime = System.currentTimeMillis();
		System.out.println("快速排序耗时："+ (endTime-startTime));
	}

	public static void main1(String[] args) {
		int [] array=new int[1000000];
		notOrderArrayRandom(array);
		//testInsertSort(array);
		//testShellSort(array);
		//testSelectSort(array);
		//testHeapSort(array);
		testQuickSort(array);
	}
	public static void main3(String[] args) {
		int [] nums={5,13,2,13,9,4,5,7,14,8,1,15};
		Arrays.sort(nums);
		int size=nums.length;
		int cnt=0;
		while(size!=0) {
			size/=2;
			cnt++;
		}
		double [] array=new double[cnt];
		size=nums.length;
		for (int i =0;i<cnt;i++) {
			array[i]=((nums[i]+nums[size-1-i])/2.0);
		}
		Arrays.sort(array);
		System.out.println(Arrays.toString(array));
		System.out.println(Arrays.toString(nums));
	}

	public static void main2(String[] args) {
		//这里用来检测排序的办法对不对
		int [] array={12,10,9,5,4,2,7,3};
		Sort.mergeSortNor(array);
		System.out.println(Arrays.toString(array));
	}

	public static void main4(String[] args) {
		int [] array={101,105,111,114,115,117,118,119,116,116,117,116,116,116,116,116,116};
		Arrays.sort(array);
		Sort.countSort(array);
		System.out.println(Arrays.toString(array));
	}

	public static void main(String[] args) {
		int [] array=new int[]{9,8,7,6,5,4,3,2,1};
		Sort.quickSort(array);
		System.out.println(Arrays.toString(array));
	}
}
